<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title> </title>
		[#include "/admin/include/head.htm"]
		<script type="text/javascript" src="${base}/resource/thirdparty/editor/kindeditor.js"></script>
		<script type="text/javascript" src="${base}/resource/js/input.js"></script>
		<script type="text/javascript">
			$(function(){
				var mainform = $("#mainform");  
				//表单底部按钮 
		    	LG.setFormDefaultBtn(f_cancel, function(){
		    	
		    		if($(this).find("option:selected").val() != "GLOBLE"){
			    		var memberIds = '';
			    		$("#memberSelect > option").each(function(i){
			    			memberIds = memberIds +$(this).val() + ",";
			    		});
			    		memberIds = memberIds.substring(0,memberIds.length-1);
			    		$("input[name='memberIds']").val(memberIds);
		    		}
		    		
		    		var $outerUrl = $('div.outerUrl').find("input[name='outerUrl']");
		    		if($(".enabledOuterUrl:checked").val() == 'true'){
		    			if($.trim($outerUrl.val()) == ''){
		    				LG.showError("请填写外部链接");
		    				return;
		    			}
		    			
		    			var regex = /(https?|ftp|file)\:\/\/(.+)/;
			    		if(!regex.test($outerUrl.val())){
			    			LG.showError("外部链接格式不正确");
			    			return;
			    		}
		    		}
		    		
		    		f_save(mainform, "b2c_site_notice_list");
				});
				
				$("#noticeType").change(function(){
					if($(this).find("option:selected").val() == "GLOBLE"){
						$("input[name='memberIds']").val('');
						$("#memberStyle").hide();
					}else{
						$("#memberStyle").show();
					}
				});
				
				$("#memberSelect").dblclick(function(){
					$(this).find("option:selected").remove();
				});
				
				$(".enabledOuterUrl").change(function(){
					var $outerUrl = $('div.outerUrl').find("input[name='outerUrl']");
					if($(this).val() == 'true'){
						$outerUrl.addClass("formText {required: true}");
						$("#content").hide();
						$('div.outerUrl').show();
					}else{
						$outerUrl.val('http://');
						$outerUrl.attr("class","");
						$("#content").show();
						$('div.outerUrl').hide();
					}
				});
				
				$("#memberUsername").autocomplete(base + "/admin/b2c/member/search.jhtml",{
					minChars: 1,
					max: 10,
					autoFill: false,
					mustMatch: false,
					matchContains: true,
					scroll:false,
					dataType:'json',
					extraParams:{  
                        keyword:function(){return $("#memberUsername").val();},
                        limit:10
                    }, 
                    parse: function(data){    
                        var rows = [];    
                        var d = data;
                        for(var i=0; i<d.length; i++){
                           rows[rows.length] = {
                           	data:d[i],
                           	value:d[i].username,
                           	result:d[i].username
                          };    
                        }    
                        return rows;    
                    },   
					highlight: function(value, term) { 
				    	return value.replace(new RegExp("("+term+")", "gi"),"<b style='color:red'>$1</b>"); 
				    },
					formatItem: function(row, i, total) {
                        var result = toResult(row.username, row.mobile, row.name);
						return result;
					},
					formatResult: function(row) {
						return row.username;
					}
				}).result(function(event, row, formatted){
					if(row){
                        var result = toResult(row.username, row.mobile, row.name);
						if($("#memberSelect").find("option[value="+row.id+"]").length == 0){
							$("#memberSelect").append('<option value="'+row.id+'">'+result+'</option>');
						}
					}
				});

                function toResult(username, mobile, name){
                    var result = '';
                    if(username && username != 'undefined'){
                        result = result +"【"+ username+"】";
                    }
                    if(name && name != 'undefined'){
                        result = result + name +"—";
                    }
                    if(mobile && mobile != 'undefined'){
                        result = result + mobile;
                    }
                    return result;
                }
			});
		</script>
	</head>
	[#if !noticeText??]
		[#assign isAdd = true /]
	[#else]
		[#assign isEdit = true /]
	[/#if]
	<body style="overflow:scroll;padding:10px;">
		<form action="[#if isAdd??]${base}/admin/b2c/siteNotice/save.jhtml[#else]${base}/admin/b2c/siteNotice/update.jhtml[/#if]" method="post" id="mainform" class="validate">
		<div id="tabcontainer" style="overflow:hidden;margin:3px;padding-bottom: 50px;">
			[#if !isAdd??]
				<input type="hidden" name="id" value="${(noticeText.id)!}"/>
			[/#if]
			<table class="inputTable2">
				<tr>
					<th>消息标题:</th>
					<td>
						<input type="text" name="title" value="${(noticeText.title)!}" class="formText {required: true}"/>
					</td>
				</tr>
				<tr>
					<th>消息类型:</th>
					<td>
						[@u.select_map id="noticeType" listKey='key' listValue='name'  value="${(noticeText.type)!}"
							headerButtom="false" list=siteNoticeTypeList
							name="type" class="{required: true}"/]
					</td>
				</tr>
				<tr>
					<th>启用外部链接:</th>
					<td>
						[@u.radio list={"true":"是", "false":"否"} 
							value="${(noticeText.enabledOuterUrl?string('true', 'false'))!'false'}"
							name="enabledOuterUrl" class="enabledOuterUrl"/]
						&nbsp;&nbsp;
						<div class="outerUrl" style="display: inline;">
							外部链接：<input type="text" name="outerUrl" value="${(noticeText.outerUrl)!'http://'}"/>
						</div>
					</td>
				</tr>
				<tr id="memberStyle">
					<th>关联通知会员</th>
					<td>
						[#if isAdd??]
							<div style="float: left">
								<dl>
									<dt>请输入会员名称模糊匹配:</dt>
									<dd><input autocomplete="off" id="memberUsername" placeholder="会员帐号" style="width:300px"/></dd>
								</dl>
							</div>
						[/#if]
						<div style="float: left;padding-left:10px;">
							[#if isAdd??]
							<span class="warnInfo"  >	
								<span class="icon">&nbsp;</span> 
								提醒：双击删除
							</span>
							<br/>
							[/#if]
							<select id="memberSelect" [#if isEdit??] disabled="disabled"[/#if] multiple="multiple" style="width:300px;height:200px">
								[#if memberList?has_content]
									[#list memberList as m]
										<option value="${m.id}">【${m.username}】${(m.name)!}</option>
									[/#list]
								[/#if]
							</select>
						</div>
						<input type="hidden" name="memberIds" />
					</td>	
				</tr>
				<tr id="content">
					<th>内容</th>
					<td>
						<textarea name="content" id="editor" style="width: 500px;">${(noticeText.content)!}</textarea>
					</td>
				</tr>
				<script>[#if noticeText?? && noticeText.enabledOuterUrl?? && noticeText.enabledOuterUrl]$("#content").hide();$('div.outerUrl').show();[#else]$("#content").show();$('div.outerUrl').hide();[/#if]</script>
			</table>
		</div>
		</form>
	</body>
	[#if noticeText?? && noticeText.type = 'GLOBLE']
		<script>$("#memberStyle").hide();</script>
	[/#if]
	
</html>